// pages/share-poster/share-poster.js
var base64 = require('../../utils/Base64.js');
var app = getApp();
var loginuid = 0;
Page({
  data:{    
      imgDomain: app.globalData.imgDomain,
      uid: 0,
      token: ''
  },
  
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    // app.dialog('签约成功', 'success');
    var that = this;
    var inviteuid = options.inviteuid;
    //调用应用实例的方法获取全局数据
    app.LoginUserInfo(function(res){
      //更新数据      
      if (res && res != -1) {
      loginuid = res.uid;
      //更新数据
      that.setData({
        uid: res.uid,
        token: res.token
      })      
      }
    }, inviteuid);
  },
  // onReady:function(){
  //   // 页面渲染完成
  // },
  // onShow:function(){
  //   // 页面显示
  // },
  // onHide:function(){
  //   // 页面隐藏
  // },

  // onUnload:function(){
  //   // 页面关闭, 返回首页
  //   var homeUrl = '/pages/index/index';
  //   wx.reLaunch({ url: homeUrl })//关闭所有页面重新读取首页
  // },

  reloadIndex: function(){
    var homeUrl = '/pages/index/index';
    wx.reLaunch({ url: homeUrl })//关闭所有页面重新读取首页
  },

  shareToPengyouquan: function (e) {
    console.log("formid: ", e.detail.formId);
    var that = this;
    app.saveFormId(e.detail.formId);//保存fromId
    
    var shareImgUrl = "http://api.artart.cn/wxxcxcode.php?&txl=1&uid=" + that.data.uid;
    this.showEWM(shareImgUrl);
    // shareImgUrl = base64.encode(shareImgUrl);
    // var url = "/pages/share-pengyouquan/share-pengyouquan?imgUrl=" + shareImgUrl;
    // wx.navigateTo({ url: url })
  },

  showEWM: function (url) {
    wx.previewImage({
      current: url,
      urls: [url]
    })
  },

  //页面分享
  onShareAppMessage: function () {
    console.log("onShareAppMessage: ", that.data.uid);
    return app.sharePage('', that.data.uid);
  },
})